<?php

function detectfilesize($size, $round='2') {
	$filesize=$size;
	for($i=0;$filesize>=1024;$i++) {
		$filesize = $filesize/1024;
	}
	$filesize = round($filesize,$round);
	switch($i) {
		case 0: $filesize = $filesize." Byte"; break;
		case 1: $filesize = $filesize." kB"; break;
		case 2: $filesize = $filesize." MB"; break;
		case 3: $filesize = $filesize." GB"; break;
		case 4: $filesize = $filesize." TB"; break;
		default: $filesize = $size." Byte"; break;
	}
	return $filesize;
}

function getdirsize($dir) {

	$size=0;
	$handle = opendir($dir);
	while (false !== ($file = readdir($handle))) {
		if ($file != "." && $file != "..") {
			if(is_dir($dir.$file)) $size = $size + getdirsize($dir.$file.'/');
			else $size=$size+filesize($dir.$file);
		}
	}
	return $size;
}

function rm_recursive($filepath){
	if (is_dir($filepath) && !is_link($filepath)){
	    if ($dh = @opendir($filepath)){
	        while (($sf = readdir($dh)) !== false){
	            if ($sf == '.' || $sf == '..'){
	                continue;
	            }
	            if (!rm_recursive($filepath.'/'.$sf)){
	                return false;
	            }
	        }
	        closedir($dh);
	    }
	    return @rmdir($filepath);
	}
	return @unlink($filepath);
}

?>